$(() => {
    let forum_id = GetQueryString("forum_id");
    let page = 1;
    let pageSize = 10;
    commentLists(page);

    function commentLists(page) {
        $.ajax({
            type: "post",
            url: url,
            data: { 'method': 'Forum|more_comments', 'forum_id':forum_id, 'page': page, 'pagelimit': pageSize },
            dataType: 'json',
            success: function(res) {
                // console.log(res);
                if (res.status == 1) {
                    let data = res.data;
                    let html = '';
                    data.forEach(item => {
                        html += `
                        <div class="commentlists">
                            <p class="commentItem">${item.nick_name}：<span>${item.content}</span></p>
                        </div>
                        `;
                    })
                    if (data.length < pageSize) {
                        $('.notMore').css('display', 'flex');
                    }
                    $('.commentWrapper').append(html);
                } else if (res.status == 2) {
                    location.href = "fox://logout";
                } else {
                    alert(res.message);
                }
            }
        });
    }

    // 下拉加载更多
    $(window).scroll(function() {
        if ($(document).scrollTop() >= $(document).height() - $(window).height() - 1) {
            // console.log('我到底了');
            if ($('.notMore').css('display') != "flex") {
                page++;
                commentLists(page);
            }
        }
    })
})